package com.ljkj.lawyer.lawyer.controller;

import com.ljkj.lawyer.lawyer.common.MessageResult;
import com.ljkj.lawyer.lawyer.common.RestResult;
import com.ljkj.lawyer.lawyer.param.card.SearchParam;
import com.ljkj.lawyer.lawyer.service.CardService;
import com.ljkj.lawyer.lawyer.service.LawyerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/lawyer/card")
public class CardController {
    @Autowired
    private CardService cardService;

    @Autowired
    private LawyerService lawyerService;

    @GetMapping("/getLawyerList")
    public RestResult getLawyerList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize) {
        return cardService.getLawyerList(pageNum,pageSize);
    }

    @PostMapping("/searchLawyerList")
    public RestResult searchLawyerList(@RequestBody SearchParam searchParam) {
        if(searchParam.getPageNum() == null || searchParam.getPageSize() == null ){
            searchParam.setPageNum(1);
            searchParam.setPageSize(10);
        }
        return cardService.searchLawyerList(searchParam);
    }

    @GetMapping("/getLastLawyerInfoByMemberId")
    public RestResult getLawyerInfoByMemberId(@RequestParam("memberId") Integer memberId) {
        return RestResult.success(lawyerService.getLastLawyerInfoByMemberId(memberId).getData());
    }

    @GetMapping("/getCommerceList")
    public RestResult getCommerceList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,@RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize) {
        return cardService.getCommerceList(pageNum,pageSize);
    }

    @PostMapping("/searchCommerceList")
    public RestResult searchCommerceList(@RequestBody SearchParam searchParam) {
        if(searchParam.getPageNum() == null || searchParam.getPageSize() == null ){
            searchParam.setPageNum(1);
            searchParam.setPageSize(10);
        }
        return cardService.searchCommerceList(searchParam);
    }

    @GetMapping("/getCommerceByMemberId")
    public RestResult getCommerceByMemberId(@RequestParam("memberId") Integer memberId) {
        return cardService.getCommerceByMemberId(memberId);
    }
}
